﻿using UnityEngine;
using System.Collections;

public class ViewToMessage : MessageViewBase
{
    public ViewToMessage()
    {
        base._classType = 2;
    }

    public override void Handle()
    {
        switch (_type)
        {
            case MessageViewType.VTM_single_explosion:
                SingleProcessExplosion((Vector2)_factor1);
                break;
        }
    }

    private void SingleProcessExplosion(Vector2 collPixel)
    {
        GamePlayScene playScene = GameCommon.GetPlayScene();
        CannonBall cannonBall = playScene._cannonBall;

        Color[] alphaColorArray = WorldmapDataMgr.GetPixelAlpha(0);

        PixelMask pixelMask = playScene._terrainLoader._PixelMask;

        int count = 500;
        int x = (int)collPixel.x;
        int y = (int)collPixel.y;

        for (int j = -(count / 2); j < count / 2; ++j)
        {
            for (int k = -(count / 2); k < count / 2; ++k)
            {
                int realPixelIdx = (x + k) + ((y - j) * 1280);

                if (realPixelIdx < 0)
                    continue;

                if (Vector2.Distance(collPixel, new Vector2(x + k, y - j)) > 70)
                    continue;

                alphaColorArray[realPixelIdx].a = 0.0f;

            }
        }
        pixelMask.UpdatePixel();

        cannonBall.Destroy();
        playScene._cannonBall = null;

        // 일단 무조건 자기 턴으로.
        playScene._inGameStateMgr.ChangeState(InGameStateManager.StateType.SingleMyTurnState);
    }
	
}
